package com.charactereducation.productcenter.service;

import com.charactereducation.module.vo.ProductEntity;
import com.charactereducation.dao.ProductEntityMapper;
import com.charactereducation.tools.myRunTime.MyRunTimeExcption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by zpc on 2017/3/31.
 */
@Service("productEntityService")
public class ProductEntityServiceImpl extends ProductEntityBase implements ProductEntityService {
    @Autowired
    ProductEntityMapper productEntityMapper;

    @Override
    public void deleteProductEntity(List<Long> productEntityIdList) {
        super.deleteProductEntity(productEntityIdList);
    }

    @Override
    @Transactional
    public ProductEntity modifyProductEntity(ProductEntity productEntity) {


        if (productEntity.getTid() == null) {
            super.insertProductEntity(productEntity);
        } else {

            super.updateProductEntity(productEntity);
        }

        return productEntity;
    }


    @Override
    public List<ProductEntity> getProductEntityList(Map<String, String> map) {
        return productEntityMapper.getProductEntityList(map);
    }


    @Override
    public ProductEntity getProductEntityByProductEntityId(Long productEntityId) {
        return productEntityMapper.getProductEntityByProductEntityId(productEntityId);
    }



    @Override
    public ProductEntity getProductEntity(Map<String, String> map) {
        ProductEntity productEntity = productEntityMapper.getProductEntity(map);

        return productEntity;
    }

    //根据活动id查询产品
    @Override
    public List<ProductEntity> getProductEntityByActivityId(Long activityId) {
        return productEntityMapper.getProductEntityByActivityId(activityId);
    }

    @Override
    public void reduceProductEntity(Long productEntityId) {
        productEntityMapper.reduceProductEntity(productEntityId);
    }

    @Override
    public Integer getProductEntityAmount(Integer productEntityAmount, Long productEntityId) {
      if(productEntityAmount==null){
          productEntityAmount=0;
      }    if(productEntityId==null){
          throw new MyRunTimeExcption("产品为空！");
      }

        productEntityAmount+=productEntityMapper.getProductEntityAmount(productEntityId);
        return productEntityAmount;
    }


}
